<?php
/**
 * ExtEvent should be used in conjunction with the modulehook component,
 * thus allowing hooks to pass over data.
 * 
 * @uses CEvent
 * @package 
 * @version $id$
 * @copyright 2010 &copy; Flavius Aspra
 * @author Flavius Aspra <flav@yet-another-project.com> 
 * @license License {@link http://yet-another-project.com/project/yap/LICENSE.txt}
 */
class ExtEvent extends CEvent {
	/**
	 * tryDefault whether to try raising the event through CEvent, the classical
	 * Yii way, or to run hooks directly, which may spare you an exception
	 * being thrown by Yii.
	 * 
	 * @var boolean
	 * @access public
	 */
	public $tryDefault = TRUE;
	/**
	 * the data being passed to the hook or returned back
	 */
	public $data = NULL;
	/**
	 * The modules this event is intended for
	 *
	 * If specified, it sends the event only to those modules
	 * @var mixed
	 */
	public $for = NULL;
	/**
	 * The module which owns this event, which must not necessarily be the sender.
	 * If the sender is a CModule or a CController, the module will be detected
	 * automatically. Otherwise you have to set it yourself.
	 * 
	 * @var object
	 * @access public
	 */
	public $module = NULL;
	public $controller = NULL;
	public $action = NULL;
	/**
	 * __construct construct the extended event
	 * 
	 * @param mixed $sender the sender
	 * @param mixed $tryDefault the value of ExtEvent::$tryDefault. Default: TRUE
	 * @param mixed $module the module which owns this event, which must not necessarily
	 * be the sender. 
	 * @access public
	 * @return void
	 */
	public function __construct($sender=NULL, $tryDefault=TRUE, $module=NULL,$for=NULL) {
		parent::__construct($sender);
		//@todo try autodetecting more of these (does it make sense?)
		$this->tryDefault = $tryDefault;
		$this->module = $module;
		$this->for = $for;
		if(NULL === $this->module) {
			if($this->sender instanceof CModule) {
				$this->module = $this->sender;
			}
			elseif($this->sender instanceof CController) {
				$this->module = $this->sender->module;
			}
		}
	}
}
